package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void insertBatch(List<OrderDetail> orderDetailList);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);


    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 处理超时订单
     */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> processTimeOutOrder(Integer status, LocalDateTime time);

    /**
     * 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    OrderVO getOrderById(Long id);

    /**
     * 待接单的数量
     */
    @Select("select count(id) from orders where status = 2")
    Integer gettoBeConfirme();
    /**
     * 待派送数量
     */
    @Select("select count(id) from orders where status = 3")
    Integer getconfirmed();

    /**
     * 派送中的数量
     */
    @Select("select count(id) from orders where status = 4")
    Integer getdeliveryInProgress();

    /**
     * 统计营业额
     */
    Double sumByTime(LocalDateTime beginTime, LocalDateTime endTime, Integer completed);

    /**
     * 统计订单数量
     */
    Integer getByTime(LocalDateTime beginTime, LocalDateTime endTime, Integer status);
}
